package action.system;

import java.util.List;

import org.springframework.security.core.context.SecurityContextHolder;

import model.security.UsrAuth;
import model.security.UsrRes;
import model.security.UsrRole;
import model.security.UsrUser;

import service.system.SystemListService;
import util.Log;

import core.action.BaseAction;
import core.security.MyUserDetail;
import exception.Exceptions;

public class SystemListAction extends BaseAction{
	private List userlists;
	private List rolelists;
	private List reslists;
	private List authlists;
	
	private List<String> role_in_auth;
	private List<String> role_not_in_auth;
	private List<String> role_all_name;
	
	private List allrole;
	
	private long userid;
	private int roleid;
	private int resid;
	private int authid;
	private SystemListService systemListService;
	private UsrUser user;
	private UsrRole role;
	private UsrRes res;
	private UsrAuth auth;
	
	private List user_now_role;
	
	public String FLAG="EDIT";

	//---------------user---------------
	public String user(){
		userlists=systemListService.get_userlist();
		super.successResultValue="systemUserList";
		Log.save("查询", "用户管理列表", "");
		return "function";
	}
	public String userDel(){
		systemListService.delete_user(userid);
		MessageJump("用户删除成功","systemList!user");
		return "message";
	}
	public String userEdit() throws Exceptions{
		if(userid==0){
			MyUserDetail userDetails = (MyUserDetail)SecurityContextHolder.getContext()
				    .getAuthentication()
				    .getPrincipal();
			userid=systemListService.getidByname(userDetails.getUsername());
		}
		user=systemListService.get_user(userid);
		
		allrole=systemListService.get_allrole();
		
		user_now_role=systemListService.get_this_roleid(userid);//当前用户的角色集

		super.successResultValue="systemUserEdit";
		return "function";
	}
	
	//---------------role--------------------
	public String role(){
		rolelists=systemListService.get_rolelist();
		//page_show=systemListService.show_rolePage();
		super.successResultValue="systemRoleList";
		return "function";
	}
	public String roleDel(){
		systemListService.delete_role(roleid);
		MessageJump("角色删除成功","systemList!role");
		return "message";
	}
	
	@SuppressWarnings("unchecked")
	public String roleEdit(){
		role=systemListService.get_role(roleid);
	
		role_in_auth=systemListService.get_this_authid(roleid);		
		role_all_name=systemListService.get_role_in_auth();

		super.successResultValue="systemRoleEdit";
		//role_not_in_auth=systemListService.get_role_in_auth(roleid,false);
		return "function";
	}
	
	//--------------res------------------------
	public String res(){
		reslists=systemListService.get_reslist();
	//	page_show=systemListService.show_resPage();
		super.successResultValue="systemResList";
		return "function";
	}
	public String resDel(){
		systemListService.delete_res(resid);
		MessageJump("资源删除成功","systemList!res");
		return "message";
	}
	public String resEdit(){
		res=systemListService.get_res(resid);
		super.successResultValue="systemResEdit";
		return "function";
	}
	
	//----------------auth---------------------
	public String auth(){
		authlists=systemListService.get_authlist();
	//	page_show=systemListService.show_authPage();
		super.successResultValue="systemAuthList";
		return "function";
	}
	public String authDel(){
		systemListService.delete_auth(authid);
		MessageJump("权限删除成功","systemList!auth");
		return "message";
	}
	public String authEdit(){
		auth=systemListService.get_auth(authid);
		super.successResultValue="systemAuthEdit";
		return "function";
	}
		
	
	public String execute(){		
		return "success";
	}
	
	public List getUserlists() {
		return userlists;
	}
	public void setUserlists(List userlists) {
		this.userlists = userlists;
	}

	public List getRolelists() {
		return rolelists;
	}

	public void setRolelists(List rolelists) {
		this.rolelists = rolelists;
	}

	public List getReslists() {
		return reslists;
	}

	public void setReslists(List reslists) {
		this.reslists = reslists;
	}

	public List getAuthlists() {
		return authlists;
	}

	public void setAuthlists(List authlists) {
		this.authlists = authlists;
	}

	public long getUserid() {
		return userid;
	}

	public void setUserid(long userid) {
		this.userid = userid;
	}

	public UsrUser getUser() {
		return user;
	}

	public void setUser(UsrUser user) {
		this.user = user;
	}
	public UsrRole getRole() {
		return role;
	}
	public void setRole(UsrRole role) {
		this.role = role;
	}
	public int getRoleid() {
		return roleid;
	}
	public void setRoleid(int roleid) {
		this.roleid = roleid;
	}
	public int getResid() {
		return resid;
	}
	public void setResid(int resid) {
		this.resid = resid;
	}
	public int getAuthid() {
		return authid;
	}
	public void setAuthid(int authid) {
		this.authid = authid;
	}
	public UsrRes getRes() {
		return res;
	}
	public void setRes(UsrRes res) {
		this.res = res;
	}
	public UsrAuth getAuth() {
		return auth;
	}
	public void setAuth(UsrAuth auth) {
		this.auth = auth;
	}
	public SystemListService getSystemListService() {
		return systemListService;
	}
	public void setSystemListService(SystemListService systemListService) {
		this.systemListService = systemListService;
	}
	public List<String> getRole_in_auth() {
		return role_in_auth;
	}
	public void setRole_in_auth(List<String> role_in_auth) {
		this.role_in_auth = role_in_auth;
	}
	public List<String> getRole_all_name() {
		return role_all_name;
	}
	public void setRole_all_name(List<String> role_all_name) {
		this.role_all_name = role_all_name;
	}
	public List getAllrole() {
		return allrole;
	}
	public void setAllrole(List allrole) {
		this.allrole = allrole;
	}

	public List<String> getRole_not_in_auth() {
		return role_not_in_auth;
	}
	public void setRole_not_in_auth(List<String> role_not_in_auth) {
		this.role_not_in_auth = role_not_in_auth;
	}
	public List getUser_now_role() {
		return user_now_role;
	}
	public void setUser_now_role(List user_now_role) {
		this.user_now_role = user_now_role;
	}


}
